package com.zhiyuancode.mqack.worker.checker;


import com.zhiyuancode.mqack.message.base.MqResendErrorCode;
import com.zhiyuancode.mqack.message.base.MqResendRuntimeException;
import com.zhiyuancode.mqack.message.base.addressAndMessage.BaseAddressAndMessage;
import com.zhiyuancode.mqack.worker.recorder.BaseRecorder;
import org.springframework.data.redis.RedisConnectionFailureException;

import java.io.IOException;
import java.util.List;

/**
 * @author 杨志远
 * email faryangsh@163.com
 * Date    2018-05-15
 */
public class BaseChecker {
    protected BaseRecorder recorder;

    protected List<? extends BaseAddressAndMessage> getMqAddressAndMessages() {
        List<? extends BaseAddressAndMessage> mqList;
        try {
            mqList = recorder.queryResendMessage();
        } catch (IOException e) {
            throw new MqResendRuntimeException(MqResendErrorCode.JSON_DESERIALIZE_EXCEPTION, e);
        } catch (RedisConnectionFailureException e) {
            throw new MqResendRuntimeException(MqResendErrorCode.REDIS_CONNECTION_EXCEPTION, e);
        } catch (Exception e) {
            throw new MqResendRuntimeException(MqResendErrorCode.UNKNOW_EXCEPTION, e);
        }
        return mqList;
    }
}
